<?php
/*
 *加盟商家定时取消订单控制器
 */
namespace Home\Controller;
use Think\Controller;
class TimingController extends Controller {
	public function index()
	{
		//获取当前商家id
		$shopid=!empty($_SESSION['shopid'])?$_SESSION['shopid']:'';
		//小于当前时间并超过24小时未付款订单
		$orderids=M()->query('SELECT orderid FROM '.C('DB_PREFIX').'order WHERE (create_time+86400) < NOW()  AND (shipping_status+pay_status+order_status)<3 
AND (shipping_status+pay_status+order_status) !=4');
		//将订单状态设置为取消
		/*echo '<pre>';
		print_r($orderids);
		echo '</pre>';die;*/
		if (!empty($orderids)) 
		{
			$order=M('order');
			$data=array('order_status'=>2,'shipping_status'=>0,'pay_status'=>'fdf');
			$order->startTrans();
			foreach ($orderids as $key => $value)
			 {
				$result=$order->where('orderid=%d',$value['orderid'])->setField($data);

				if($result !==false){
					$order->commit();
				}else{
					$order->rollback();
					break;
				}

			}
			//订单状态修改end
			if($result !==false){
				echo '取消订单成功';
			}
		}
	}



}